﻿<cfscript>
/** 
* @hint "depBaseInfo - 指定专业、年级的培养方案是否存在" 
*/ 

component 
	extends="MachII.framework.EventFilter" 
	displayname="acadmicManager.filters.senate.programSchemaExistsFilter" 
	output=false 
	{
	
	/*
	* @hint "Configures this filter as part of the Mach-II framework" 
	*/
	public void function configure() output=false {} 
	
	/*
	* @hint "Filters event and returns a boolean to Mach-II indicating whether or not the event queue should proceed.  If not, the event queue is cleared and a new event is announced."
	* 
	* @event "MachII Event Object"
	* @eventContext "MachII EventContext Object"
	*/
	public boolean function filterEvent ( required MachII.framework.Event event, required MachII.framework.EventContext eventContext ) output=false {
		
		var grade = event.getArg("Edition");
		var subjectId = event.getArg("SubjectID");

		var sql = "	SELECT
						sbj.sbj_id,sbj.sbj_name
					FROM
						t_subject sbj
					WHERE
						sbj.sbj_id = :subjectId ";
		
		var queryObj = new Query(datasource = application.dnsSlave);
		
		queryObj.addParam(name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar");
		
		var rs_subject = queryObj.execute(sql=sql).getResult();

		sql = "	SELECT
					sc.shm_id
				FROM
					t_schema sc
				WHERE
					sc.sbj_id = :subjectId 
					AND
					sc.grade = :grade ";
		
		queryObj = new Query(datasource = application.dnsSlave);
		
		queryObj.addParam(name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar");
		queryObj.addParam(name="grade", value=grade, cfsqltype="cf_sql_char");
		
		var rs_schema = queryObj.execute(sql=sql).getResult();
		
		if ( rs_schema.recordCount ) {
			return true;
		} else {
			/* 发送培养方案不存在提示 */
			event.setArg("msgWarn", "您指定《" & rs_subject.sbj_name & "专业 - " & grade & " 版》培养方案不存在");
			announceEvent("programSchemaNotExists", event.getArgs());
		}
		
		return false;
	}
	
}

</cfscript>